import { defineStore } from 'pinia'
import { defaultSettings } from './app-state'
import { getMenuList } from '@/api/user'

const useAppStore = defineStore('app', {
  state: () => {
    return defaultSettings
  },

  actions: {
    /**
     * 设置菜单宽
     * @param width 菜单框
     */
    setMenuWidth(width: number) {
      this.menuWidth = width
    },

    /**
     * 获取后台路由数据
     */
    async getServerMenuList() {
      const res = await getMenuList()
      //保存路由数据
      this.serverMenu = res.data
    },

    /**
     * 请求用户权限
     */
    async getServicePermissionList() {
      this.permissionList = [
        'sys:user:add',
        'sys:user:delete',
        'sys:user:update',
        'sys:user:detail',
      ]
    },
  },
})

export default useAppStore
